package com.itcast.jdbc.test03;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class DatasourceUtils {
    private static DataSource dataSource;
    static {
        //1.直接创建一个连接池对象

        DruidDataSource data=new DruidDataSource();
        ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
        //ResourceBundle工具类 官方提供 就是读取properties配置文件 而且不需要写后缀名
        data.setDriverClassName(bundle.getString("jdbc.driverClassName"));
        data.setUrl(bundle.getString("jdbc.url"));
        data.setUsername(bundle.getString("jdbc.username"));
        data.setPassword(bundle.getString("jdbc.password"));

        dataSource=data;
    }
    public static Connection getConnection() throws SQLException {


        return dataSource.getConnection();
    }

}
